// 全排列

package Leetcode;

import java.util.ArrayList;
import java.util.List;

class solution_046 {
    public List<List<Integer>> permute(int[] nums) {
        List<List<Integer>> result = new ArrayList<>();
        link(nums, 0, result, new ArrayList<>());
        return result;
    }

    public void link(int[] nums, int length, List<List<Integer>> result, List<Integer> combination) {
        if (length == nums.length)
            result.add(new ArrayList<>() {
                {
                    addAll(combination);
                }
            });
        for (int i = 0; i < nums.length; i++) {
            if (combination.contains(nums[i]) == false) {
                combination.add(nums[i]);
                link(nums, length + 1, result, combination);
                combination.remove(combination.size() - 1);
            }
        }
    }
}

public class Solution046 {

}
